package com.game.src.main;

import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class Player {

	private double x;
	private double y;

	private double velX = 0;
	private double velY = 0;
	
	private double ticksToNextShot;
	private double ticksBetweenShots = 20;

	private Textures tex;
	
	boolean isShooting = false;
	
	private Game game;
	
	
	private int score = 0;
	private int health = 100;

	public Player(Game game, double x, double y, Textures tex) {
		this.x = x;
		this.y = y;
		this.tex = tex;
		this.game = game;
	}

	public void tick() {
		ticksToNextShot--;
		x += velX;
		y += velY;
		
		if (x <= 0){
			x = 0;
		}
		if(y <= 0){
			y = 0;
		}	
		if(x >= 640 - 55){
			x = 640 - 55;
		}
		if(y >= 480 - 64){
			y = 480 - 64;
		}	
		
		if(isShooting&&ticksToNextShot<0){
			shoot();
			ticksToNextShot = ticksBetweenShots;
		}
	}
	
	public void shoot(){
		Controller c = game.getController();
		c.addBullet(new Bullet(getX() + 28, getY() - 13, tex));
		c.addBullet(new Bullet(getX() - 28, getY() - 13, tex));
		if(score>1000){
			ticksBetweenShots = 15;
			if(score>2000){
				c.addBullet(new Bullet(getX() - 28, getY() - 13, tex, -2,8));
				c.addBullet(new Bullet(getX() + 28, getY() - 13, tex, 2,8));
				if(score>4000){
					ticksBetweenShots = 10;
					if(score>10000){
						ticksBetweenShots = 8;
						if(score>15000){
							c.addBullet(new Bullet(getX() - 28, getY() - 13, tex, -4,8));
							c.addBullet(new Bullet(getX() + 28, getY() - 13, tex, 4,8));
							
							if(score>50000){
								ticksBetweenShots = 6;
								c.addBullet(new Bullet(getX() - 28, getY() - 13, tex, -6,8));
								c.addBullet(new Bullet(getX() + 28, getY() - 13, tex, 6,8));
								if(score>200000){
									ticksBetweenShots = 5;
								}
							}
							
						}
					}
				}
			}
		}
		
	}

	public void render(Graphics g) {
		g.drawImage(tex.player, (int) x, (int) y, null);
	}

	public double getX() {
		return x;
	}

	public double getY() {
		return y;
	}

	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public void setVelX(double velX) {
		this.velX = velX;
	}

	public void setVelY(double velY) {
		this.velY = velY;
	}

	/**
	 * @return the isShooting
	 */
	public boolean isShooting() {
		return isShooting;
	}

	/**
	 * @param isShooting the isShooting to set
	 */
	public void setShooting(boolean isShooting) {
		this.isShooting = isShooting;
	}

	/**
	 * @return the score
	 */
	public int getScore() {
		return score;
	}

	/**
	 * @param score the score to set
	 */
	public void setScore(int score) {
		this.score = score;
	}

	/**
	 * @return the health
	 */
	public int getHealth() {
		return health;
	}

	/**
	 * @param health the health to set
	 */
	public void setHealth(int health) {
		this.health = health;
	}
	
	
}
